Arrays are frequently used data structures in computer systems. A common form of array data structure includes elements that are the same size, a length field indicating the number of elements in the array, and a header. To access an element in an array, a processor is typically required to determine the address of the starting location of the array elements, multiply the array element size by the index of the element to be accessed, add the multiplication result to the array base address to compute an array element address, and read from or write to the array element address. Each of the steps translates into one or more instructions in the machine language. As used herein, an instruction refers to a single operation of a processor as defined by the processor's instruction set architecture (ISA). The number of instructions involved makes array access a rather expensive function.
In some instances the index given for array access may exceed the number of elements in the array. If unchecked, such out-of-bounds access can lead to memory corruption. Many existing processor architectures, however, do not implement array boundary check at the instruction level. Thus, unless the array boundary check occurs at a higher level (such as at the application level), memory corruption due to invalid array access may not be easily prevented. It would be useful, therefore, to have a reliable way of preventing invalid array access. Furthermore, it would be desirable to implement array access instructions more efficiently.